<template>
  <Button  disabled type="error" @click="deletePort">删除</Button>
</template>
<script>

import axios from "axios";

export default {
  name: 'DeletePort',
  inject:['reload'],
  props: ['id'],
  methods: {
    deletePort() {
      this.$Modal.confirm({
        title: '提示',
        content: '<p>你确定要删除吗?</p>',
        onOk: () => {
          this.delete();
        },
        onCancel: () => {
          this.$Message.info('已取消');
        },
      });
    },
    async delete() {
      try {
        const response = await axios.post(`http://172.30.53.223:8888/api/deleteport?id=${this.id}`);
        console.log(this.id)
        if (response.status === 200) {
          this.$Message.success({ background: true, content: '删除成功' });
          this.reload()
        } else {
          throw new Error('Failed to delete.');
        }
      }catch (error) {
        console.error(error);
        this.$Message.error({ background: true, content: '删除失败' });
      }
      console.log(this.id)
    },
  },
};
</script>